import React, { useState, useEffect } from 'react';
import { useParams, useNavigate } from 'react-router-dom';
import {
  Card,
  Row,
  Col,
  Avatar,
  Button,
  Tag,
  Descriptions,
  Space,
  Modal,
  Form,
  Input,
  Select,
  message,
  Typography,
  Divider,
  Spin,
  Empty,
  InputNumber,
  DatePicker,
  Switch,
} from 'antd';
import {
  ArrowLeftOutlined,
  EditOutlined,
  MessageOutlined,
  DeleteOutlined,
  UserOutlined,
  BankOutlined,
  HeartOutlined,
  CheckCircleOutlined,
  CloseCircleOutlined,
  PlusOutlined,
  MinusCircleOutlined,
} from '@ant-design/icons';
import type { 
  UserProfile, 
  MatePreferenceDetail, 
  SyncUserprofileRequest, 
  SyncMatePreferenceRequest,
  QueryUserprofileRequest,
  QueryMatePreferenceRequest,
  RelationDetail
} from '@/types';
import { formatDate, getAvatarUrl } from '@/utils';
import { userAPI } from '@/services/api';
import dayjs from 'dayjs';

const { Title, Text } = Typography;
const { TextArea } = Input;

const UserDetail: React.FC = () => {
  const { id } = useParams<{ id: string }>();
  const navigate = useNavigate();
  const [loading, setLoading] = useState(false);
  const [user, setUser] = useState<UserProfile | null>(null);
  const [matePreference, setMatePreference] = useState<MatePreferenceDetail | null>(null);
  const [editProfileModalVisible, setEditProfileModalVisible] = useState(false);
  const [editPreferenceModalVisible, setEditPreferenceModalVisible] = useState(false);
  const [messageModalVisible, setMessageModalVisible] = useState(false);
  const [profileForm] = Form.useForm();
  const [preferenceForm] = Form.useForm();

  // 获取用户档案信息
  const fetchUserProfile = async (userNum: number) => {
    try {
      const request: QueryUserprofileRequest = {
        userNumList: [userNum]
      };
      
      const response = await userAPI.getUserProfileList(request);
      
      if (response && response.code === 0 && response.data.userprofileList.length > 0) {
        const userData = response.data.userprofileList[0];
        setUser(userData);
      } else {
        message.error('获取用户档案失败');
      }
    } catch (error) {
      console.error('获取用户档案失败:', error);
      message.error('获取用户档案失败');
    }
  };

  // 获取择偶偏好信息
  const fetchMatePreference = async (userNum: number) => {
    try {
      const request: QueryMatePreferenceRequest = {
        userNumList: [userNum]
      };
      
      const response = await userAPI.queryMatePreference(request);
      
      if (response && response.code === 0 && response.data.matePreferenceList.length > 0) {
        const preferenceData = response.data.matePreferenceList[0];
        setMatePreference(preferenceData);
      } else {
        // 择偶偏好可能不存在，不显示错误
        setMatePreference(null);
      }
    } catch (error) {
      console.error('获取择偶偏好失败:', error);
      setMatePreference(null);
    }
  };

  // 获取用户详细信息
  const fetchUserDetail = async (userNum: number) => {
    try {
      setLoading(true);
      await Promise.all([
        fetchUserProfile(userNum),
        fetchMatePreference(userNum)
      ]);
    } catch (error) {
      console.error('获取用户详情失败:', error);
      message.error('获取用户信息失败');
      navigate('/user/list');
    } finally {
      setLoading(false);
    }
  };

  // 编辑用户档案
  const handleEditProfile = () => {
    if (user) {
      profileForm.setFieldsValue({
        name: user.name,
        gender: user.gender,
        height: user.height,
        weight: user.weight,
        birthDate: user.birthDate ? dayjs(user.birthDate) : null,
        maritalStatus: user.maritalStatus,
        education: user.education,
        occupation: user.occupation,
        hometown: user.hometown,
        currentResidence: user.currentResidence,
        isPartyMember: user.isPartyMember,
        annualIncome: user.assets?.annualIncome || 0,
        car: user.assets?.car || '无',
        house: user.assets?.house || '无',
        familyType: user.familyMembers?.familyType || '',
        fatherAge: user.familyMembers?.fatherDetail?.age,
        fatherDesc: user.familyMembers?.fatherDetail?.desc || '',
        motherAge: user.familyMembers?.motherDetail?.age,
        motherDesc: user.familyMembers?.motherDetail?.desc || '',
        otherMembers: user.familyMembers?.otherDetail || [],
      });
    }
    setEditProfileModalVisible(true);
  };

  // 保存用户档案
  const handleSaveProfile = async () => {
    try {
      const values = await profileForm.validateFields();
      setLoading(true);

      if (!user) return;

      const requestData: SyncUserprofileRequest = {
        userNum: user.userNum,
        name: values.name,
        gender: values.gender,
        height: values.height,
        weight: values.weight,
        birthDate: values.birthDate ? dayjs(values.birthDate).format('YYYY-MM-DD') : '',
        maritalStatus: values.maritalStatus,
        assets: {
          annualIncome: values.annualIncome || 0,
          car: values.car || '无',
          house: values.house || '无',
        },
        education: values.education,
        occupation: values.occupation,
        isPartyMember: values.isPartyMember || false,
        hometown: values.hometown,
        currentResidence: values.currentResidence,
        familyMembers: {
          familyType: values.familyType || '',
          fatherDetail: {
            age: values.fatherAge,
            desc: values.fatherDesc || '',
          },
          motherDetail: {
            age: values.motherAge,
            desc: values.motherDesc || '',
          },
          otherDetail: values.otherMembers || [],
        },
        createUser: 'admin',
        modifyUser: 'admin',
      };

      const response = await userAPI.syncUserProfile(requestData);

      if (response && response.code === 0) {
        message.success('用户档案修改成功！');
        setEditProfileModalVisible(false);
        // 重新获取用户信息
        await fetchUserProfile(user.userNum);
      } else {
        message.error(response?.msg || '修改失败');
      }
    } catch (error) {
      console.error('保存用户档案失败:', error);
      message.error('保存失败，请检查表单');
    } finally {
      setLoading(false);
    }
  };

  // 编辑择偶偏好
  const handleEditPreference = () => {
    if (matePreference) {
      preferenceForm.setFieldsValue({
        standards: matePreference.standards || '',
        minAge: matePreference.ageRange?.minAge,
        maxAge: matePreference.ageRange?.maxAge,
        minBrithday: matePreference.ageRange?.minBrithday || '',
        maxBrithday: matePreference.ageRange?.maxBrithday || '',
        minHeight: matePreference.heightRange?.minHeight,
        maxHeight: matePreference.heightRange?.maxHeight,
        minWeight: matePreference.weightRange?.minWeight,
        maxWeight: matePreference.weightRange?.maxWeight,
        minIncome: matePreference.incomeRange?.minIncome,
        maxIncome: matePreference.incomeRange?.maxIncome,
        minEducation: matePreference.educationRange?.minEducation || '',
        maxEducation: matePreference.educationRange?.maxEducation || '',
        occupationRequire: matePreference.occupationRequire || [],
        hometownRequired: matePreference.hometownRequired || [],
        currentResidenceRequired: matePreference.currentResidenceRequired || [],
        personalityTraits: matePreference.personalityTraits || [],
        otherRequired: matePreference.otherRequired || [],
      });
    } else {
      // 如果没有择偶偏好，设置默认值
      preferenceForm.resetFields();
    }
    setEditPreferenceModalVisible(true);
  };

  // 保存择偶偏好
  const handleSavePreference = async () => {
    try {
      const values = await preferenceForm.validateFields();
      setLoading(true);

      if (!user) return;

      const requestData: SyncMatePreferenceRequest = {
        matePreference: {
          userNum: user.userNum,
          standards: values.standards || '',
          ageRange: {
            minAge: values.minAge,
            maxAge: values.maxAge,
            minBrithday: values.minBrithday || '',
            maxBrithday: values.maxBrithday || '',
          },
          heightRange: {
            minHeight: values.minHeight,
            maxHeight: values.maxHeight,
          },
          weightRange: {
            minWeight: values.minWeight,
            maxWeight: values.maxWeight,
          },
          incomeRange: {
            minIncome: values.minIncome,
            maxIncome: values.maxIncome,
          },
          educationRange: {
            minEducation: values.minEducation || '',
            maxEducation: values.maxEducation || '',
          },
          occupationRequire: values.occupationRequire || [],
          hometownRequired: values.hometownRequired || [],
          currentResidenceRequired: values.currentResidenceRequired || [],
          personalityTraits: values.personalityTraits || [],
          otherRequired: values.otherRequired || [],
          createUser: 'admin',
          modifyUser: 'admin',
        },
      };

      const response = await userAPI.syncMatePreference(requestData);

      if (response && response.code === 0) {
        message.success('择偶偏好修改成功！');
        setEditPreferenceModalVisible(false);
        // 重新获取择偶偏好信息
        await fetchMatePreference(user.userNum);
      } else {
        message.error(response?.msg || '修改失败');
      }
    } catch (error) {
      console.error('保存择偶偏好失败:', error);
      message.error('保存失败，请检查表单');
    } finally {
      setLoading(false);
    }
  };

  const handleSendMessage = async (messageData: any) => {
    try {
      setLoading(true);
      
      // 模拟发送消息
      await new Promise(resolve => setTimeout(resolve, 1000));
      
      message.success('消息发送成功');
      setMessageModalVisible(false);
    } catch (error) {
      message.error('发送失败');
    } finally {
      setLoading(false);
    }
  };

  const handleMarkAsHighQuality = () => {
    Modal.confirm({
      title: '确定要标记为优质用户吗？',
      content: '标记后该用户将获得更多曝光机会',
      onOk: () => {
        message.success('已标记为优质用户');
      },
    });
  };

  const handleBlock = () => {
    Modal.confirm({
      title: '确定要拉黑该用户吗？',
      content: '拉黑后用户将无法正常使用平台功能',
      onOk: () => {
        message.success('用户已被拉黑');
      },
    });
  };

  useEffect(() => {
    if (id) {
      const userNum = parseInt(id);
      if (!isNaN(userNum)) {
        fetchUserDetail(userNum);
      } else {
        message.error('无效的用户编号');
        navigate('/user/list');
      }
    }
  }, [id, navigate]);

  if (loading) {
    return (
      <div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', minHeight: '400px' }}>
        <Spin size="large" />
      </div>
    );
  }

  if (!user) {
    return (
      <div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', minHeight: '400px' }}>
        <Empty description="用户信息不存在" />
      </div>
    );
  }

  return (
    <div className="page-container">
      {/* 头部操作栏 */}
      <div style={{ marginBottom: '24px', display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
        <Space>
          <Button icon={<ArrowLeftOutlined />} onClick={() => navigate(-1)}>
            返回
          </Button>
          <Title level={4} style={{ margin: 0 }}>
            用户详情 - {user?.name || ''}
          </Title>
          <Tag color="blue">编号: {user?.userNum || ''}</Tag>
        </Space>
        <Space>
          <Button icon={<MessageOutlined />} onClick={() => setMessageModalVisible(true)}>
            发送通知
          </Button>
          <Button onClick={handleMarkAsHighQuality}>
            标记优质用户
          </Button>
          <Button danger icon={<DeleteOutlined />} onClick={handleBlock}>
            拉黑用户
          </Button>
        </Space>
      </div>

      <Row gutter={[24, 24]}>
        {/* 基本信息 */}
        <Col xs={24} lg={8}>
          <Card title="基本信息">
            <div style={{ textAlign: 'center', marginBottom: '24px' }}>
              <Avatar
                size={120}
                src={getAvatarUrl(undefined, user?.gender === '男' ? 'male' : 'female')}
                icon={<UserOutlined />}
              />
              <Title level={4} style={{ marginTop: '16px', marginBottom: '8px' }}>
                {user?.name}
              </Title>
              <Text type="secondary">
                {user?.age}岁 • {user?.gender} • {user?.currentResidence}
              </Text>
              <div style={{ marginTop: '8px' }}>
                <Text type="secondary">
                  {user?.chineseZodiac && `${user.chineseZodiac} • `}
                  {user?.maritalStatus}
                </Text>
              </div>
            </div>

            <Descriptions column={1} size="small">
              <Descriptions.Item label="生日">
                {user?.birthDate}
              </Descriptions.Item>
              <Descriptions.Item label="学历">
                {user?.education}
              </Descriptions.Item>
              <Descriptions.Item label="职业">
                <BankOutlined style={{ marginRight: '8px' }} />
                {user?.occupation}
              </Descriptions.Item>
              <Descriptions.Item label="身高/体重">
                {user?.height}cm / {user?.weight}斤
              </Descriptions.Item>
              <Descriptions.Item label="年收入">
                {user?.assets?.annualIncome || 0}万元
              </Descriptions.Item>
              <Descriptions.Item label="籍贯">
                {user?.hometown}
              </Descriptions.Item>
              <Descriptions.Item label="是否党员">
                {user?.isPartyMember ? '是' : '否'}
              </Descriptions.Item>
              <Descriptions.Item label="车子状态">
                {user?.assets?.car || '无'}
              </Descriptions.Item>
              <Descriptions.Item label="房子状态">
                {user?.assets?.house || '无'}
              </Descriptions.Item>
            </Descriptions>
          </Card>
        </Col>

        {/* 详细信息 */}
        <Col xs={24} lg={16}>
          {/* 资料详情 */}
          <Card 
            title="资料详情" 
            extra={
              <Button 
                type="primary" 
                icon={<EditOutlined />} 
                onClick={handleEditProfile}
              >
                编辑资料
              </Button>
            }
            style={{ marginBottom: '24px' }}
          >
            <Row gutter={[24, 24]}>
              <Col span={24}>
                <Title level={5}>家庭成员信息</Title>
                <Descriptions column={2} bordered size="small">
                  {user?.familyMembers?.familyType && (
                    <Descriptions.Item label="家庭类型" span={2}>
                      {user.familyMembers.familyType}
                    </Descriptions.Item>
                  )}
                  {user?.familyMembers?.fatherDetail && (
                    <>
                      <Descriptions.Item label="父亲年龄">
                        {user.familyMembers.fatherDetail.age}岁
                      </Descriptions.Item>
                      <Descriptions.Item label="父亲情况">
                        {user.familyMembers.fatherDetail.desc}
                      </Descriptions.Item>
                    </>
                  )}
                  {user?.familyMembers?.motherDetail && (
                    <>
                      <Descriptions.Item label="母亲年龄">
                        {user.familyMembers.motherDetail.age}岁
                      </Descriptions.Item>
                      <Descriptions.Item label="母亲情况">
                        {user.familyMembers.motherDetail.desc}
                      </Descriptions.Item>
                    </>
                  )}
                </Descriptions>
                
                {user?.familyMembers?.otherDetail && user.familyMembers.otherDetail.length > 0 && (
                  <div style={{ marginTop: '16px' }}>
                    <Title level={6}>其他家庭成员</Title>
                    {user.familyMembers.otherDetail.map((member, index) => (
                      <div key={index} style={{ marginBottom: '8px' }}>
                        <Text>{member.age}岁 - {member.desc}</Text>
                      </div>
                    ))}
                  </div>
                )}
              </Col>
            </Row>
          </Card>

          {/* 择偶标准 */}
          <Card 
            title="择偶标准" 
            extra={
              <Button 
                type="primary" 
                icon={<HeartOutlined />} 
                onClick={handleEditPreference}
              >
                编辑择偶标准
              </Button>
            }
          >
            {matePreference ? (
              <Row gutter={[24, 24]}>
                {matePreference.standards && (
                  <Col span={24}>
                    <Title level={5}>择偶标准描述</Title>
                    <Text>{matePreference.standards}</Text>
                  </Col>
                )}
                
                <Col span={24}>
                  <Title level={5}>基本要求</Title>
                  <Descriptions column={2} bordered size="small">
                    <Descriptions.Item label="年龄范围">
                      {matePreference.ageRange?.minAge || '不限'} - {matePreference.ageRange?.maxAge || '不限'}岁
                    </Descriptions.Item>
                    <Descriptions.Item label="身高范围">
                      {matePreference.heightRange?.minHeight || '不限'} - {matePreference.heightRange?.maxHeight || '不限'}cm
                    </Descriptions.Item>
                    <Descriptions.Item label="体重范围">
                      {matePreference.weightRange?.minWeight || '不限'} - {matePreference.weightRange?.maxWeight || '不限'}斤
                    </Descriptions.Item>
                    <Descriptions.Item label="收入范围">
                      {matePreference.incomeRange?.minIncome || '不限'} - {matePreference.incomeRange?.maxIncome || '不限'}万元
                    </Descriptions.Item>
                    <Descriptions.Item label="学历要求">
                      {matePreference.educationRange?.minEducation || '不限'} - {matePreference.educationRange?.maxEducation || '不限'}
                    </Descriptions.Item>
                  </Descriptions>
                </Col>
                
                <Col span={24}>
                  <Title level={5}>职业要求</Title>
                  <Space wrap>
                    {matePreference.occupationRequire && matePreference.occupationRequire.length > 0 ? (
                      matePreference.occupationRequire.map((occupation, index) => (
                        <Tag key={index} color="blue">{occupation}</Tag>
                      ))
                    ) : (
                      <Text type="secondary">无特殊要求</Text>
                    )}
                  </Space>
                </Col>
                
                <Col span={24}>
                  <Title level={5}>地域要求</Title>
                  <Row gutter={16}>
                    <Col span={12}>
                      <Text strong>籍贯要求：</Text>
                      <div style={{ marginTop: '8px' }}>
                        <Space wrap>
                          {matePreference.hometownRequired && matePreference.hometownRequired.length > 0 ? (
                            matePreference.hometownRequired.map((hometown, index) => (
                              <Tag key={index} color="green">{hometown}</Tag>
                            ))
                          ) : (
                            <Text type="secondary">无特殊要求</Text>
                          )}
                        </Space>
                      </div>
                    </Col>
                    <Col span={12}>
                      <Text strong>工作地要求：</Text>
                      <div style={{ marginTop: '8px' }}>
                        <Space wrap>
                          {matePreference.currentResidenceRequired && matePreference.currentResidenceRequired.length > 0 ? (
                            matePreference.currentResidenceRequired.map((residence, index) => (
                              <Tag key={index} color="orange">{residence}</Tag>
                            ))
                          ) : (
                            <Text type="secondary">无特殊要求</Text>
                          )}
                        </Space>
                      </div>
                    </Col>
                  </Row>
                </Col>
                
                <Col span={24}>
                  <Title level={5}>个性特征要求</Title>
                  <Space wrap>
                    {matePreference.personalityTraits && matePreference.personalityTraits.length > 0 ? (
                      matePreference.personalityTraits.map((trait, index) => (
                        <Tag key={index} color="purple">{trait}</Tag>
                      ))
                    ) : (
                      <Text type="secondary">无特殊要求</Text>
                    )}
                  </Space>
                </Col>
                
                {matePreference.otherRequired && matePreference.otherRequired.length > 0 && (
                  <Col span={24}>
                    <Title level={5}>其他要求</Title>
                    <Space wrap>
                      {matePreference.otherRequired.map((other, index) => (
                        <Tag key={index} color="default">{other}</Tag>
                      ))}
                    </Space>
                  </Col>
                )}
              </Row>
            ) : (
              <Empty description="暂无择偶偏好信息" />
            )}
          </Card>
        </Col>
      </Row>

      {/* 编辑用户档案弹窗 */}
      <Modal
        title="编辑用户档案"
        open={editProfileModalVisible}
        onOk={handleSaveProfile}
        onCancel={() => setEditProfileModalVisible(false)}
        confirmLoading={loading}
        width={1000}
        style={{ top: 20 }}
        bodyStyle={{ maxHeight: '70vh', overflowY: 'auto' }}
      >
        <Form form={profileForm} layout="vertical">
          <Divider orientation="left">基本信息</Divider>
          
          <Row gutter={16}>
            <Col span={8}>
              <Form.Item
                label="姓名"
                name="name"
                rules={[{ required: true, message: '请输入姓名' }]}
              >
                <Input placeholder="请输入姓名" />
              </Form.Item>
            </Col>
            <Col span={8}>
              <Form.Item
                label="性别"
                name="gender"
                rules={[{ required: true, message: '请选择性别' }]}
              >
                <Select placeholder="请选择性别">
                  <Select.Option value="男">男</Select.Option>
                  <Select.Option value="女">女</Select.Option>
                </Select>
              </Form.Item>
            </Col>
            <Col span={8}>
              <Form.Item
                label="生日"
                name="birthDate"
                rules={[{ required: true, message: '请选择生日' }]}
              >
                <DatePicker
                  placeholder="请选择生日"
                  style={{ width: '100%' }}
                  format="YYYY-MM-DD"
                />
              </Form.Item>
            </Col>
          </Row>

          <Row gutter={16}>
            <Col span={8}>
              <Form.Item
                label="身高 (厘米)"
                name="height"
                rules={[{ required: true, message: '请输入身高' }]}
              >
                <InputNumber
                  placeholder="请输入身高"
                  min={100}
                  max={250}
                  style={{ width: '100%' }}
                />
              </Form.Item>
            </Col>
            <Col span={8}>
              <Form.Item
                label="体重 (斤)"
                name="weight"
                rules={[{ required: true, message: '请输入体重' }]}
              >
                <InputNumber
                  placeholder="请输入体重"
                  min={50}
                  max={500}
                  style={{ width: '100%' }}
                />
              </Form.Item>
            </Col>
            <Col span={8}>
              <Form.Item
                label="婚姻状态"
                name="maritalStatus"
                rules={[{ required: true, message: '请选择婚姻状态' }]}
              >
                <Select placeholder="请选择婚姻状态">
                  <Select.Option value="未婚">未婚</Select.Option>
                  <Select.Option value="离异">离异</Select.Option>
                  <Select.Option value="丧偶">丧偶</Select.Option>
                </Select>
              </Form.Item>
            </Col>
          </Row>

          <Row gutter={16}>
            <Col span={8}>
              <Form.Item
                label="教育经历"
                name="education"
                rules={[{ required: true, message: '请选择教育经历' }]}
              >
                <Select placeholder="请选择教育经历">
                  <Select.Option value="小学">小学</Select.Option>
                  <Select.Option value="初中">初中</Select.Option>
                  <Select.Option value="中专">中专</Select.Option>
                  <Select.Option value="高中">高中</Select.Option>
                  <Select.Option value="大专">大专</Select.Option>
                  <Select.Option value="本科">本科</Select.Option>
                  <Select.Option value="硕士">硕士</Select.Option>
                  <Select.Option value="博士">博士</Select.Option>
                  <Select.Option value="博士后">博士后</Select.Option>
                </Select>
              </Form.Item>
            </Col>
            <Col span={8}>
              <Form.Item
                label="职业"
                name="occupation"
                rules={[{ required: true, message: '请选择职业' }]}
              >
                <Select placeholder="请选择职业">
                  <Select.Option value="公务员">公务员</Select.Option>
                  <Select.Option value="教师">教师</Select.Option>
                  <Select.Option value="医生">医生</Select.Option>
                  <Select.Option value="护士">护士</Select.Option>
                  <Select.Option value="律师">律师</Select.Option>
                  <Select.Option value="法官">法官</Select.Option>
                  <Select.Option value="警察">警察</Select.Option>
                  <Select.Option value="自由职业者">自由职业者</Select.Option>
                  <Select.Option value="经商">经商</Select.Option>
                </Select>
              </Form.Item>
            </Col>
            <Col span={8}>
              <Form.Item
                label="是否党员"
                name="isPartyMember"
                valuePropName="checked"
              >
                <Switch checkedChildren="是" unCheckedChildren="否" />
              </Form.Item>
            </Col>
          </Row>

          <Row gutter={16}>
            <Col span={8}>
              <Form.Item
                label="籍贯"
                name="hometown"
                rules={[{ required: true, message: '请选择籍贯' }]}
              >
                <Select placeholder="请选择籍贯">
                  <Select.Option value="广德">广德</Select.Option>
                  <Select.Option value="郎溪">郎溪</Select.Option>
                  <Select.Option value="宁国">宁国</Select.Option>
                  <Select.Option value="宣城">宣城</Select.Option>
                </Select>
              </Form.Item>
            </Col>
            <Col span={8}>
              <Form.Item
                label="现居住地/工作地"
                name="currentResidence"
                rules={[{ required: true, message: '请选择现居住地' }]}
              >
                <Select placeholder="请选择现居住地">
                  <Select.Option value="上海">上海</Select.Option>
                  <Select.Option value="杭州">杭州</Select.Option>
                  <Select.Option value="合肥">合肥</Select.Option>
                  <Select.Option value="北京">北京</Select.Option>
                  <Select.Option value="南京">南京</Select.Option>
                  <Select.Option value="芜湖">芜湖</Select.Option>
                </Select>
              </Form.Item>
            </Col>
          </Row>

          <Divider orientation="left">个人资产状态</Divider>
          
          <Row gutter={16}>
            <Col span={8}>
              <Form.Item
                label="年收入 (万元)"
                name="annualIncome"
                rules={[{ required: true, message: '请输入年收入' }]}
              >
                <InputNumber
                  placeholder="请输入年收入"
                  min={0}
                  step={0.1}
                  style={{ width: '100%' }}
                />
              </Form.Item>
            </Col>
            <Col span={8}>
              <Form.Item
                label="车子状态"
                name="car"
                rules={[{ required: true, message: '请选择车子状态' }]}
              >
                <Select placeholder="请选择车子状态">
                  <Select.Option value="全款">全款</Select.Option>
                  <Select.Option value="按揭">按揭</Select.Option>
                  <Select.Option value="无">无</Select.Option>
                  <Select.Option value="随时买">随时买</Select.Option>
                </Select>
              </Form.Item>
            </Col>
            <Col span={8}>
              <Form.Item
                label="房子状态"
                name="house"
                rules={[{ required: true, message: '请选择房子状态' }]}
              >
                <Select placeholder="请选择房子状态">
                  <Select.Option value="城区全款房">城区全款房</Select.Option>
                  <Select.Option value="城区按揭房">城区按揭房</Select.Option>
                  <Select.Option value="乡镇房">乡镇房</Select.Option>
                  <Select.Option value="随时买">随时买</Select.Option>
                </Select>
              </Form.Item>
            </Col>
          </Row>

          <Divider orientation="left">家庭成员信息</Divider>
          
          <Row gutter={16}>
            <Col span={24}>
              <Form.Item
                label="家庭类型备注"
                name="familyType"
              >
                <Input placeholder="如：单亲家庭等特殊情况" />
              </Form.Item>
            </Col>
          </Row>

          <Row gutter={16}>
            <Col span={12}>
              <Card title="父亲情况" size="small">
                <Form.Item
                  label="年龄"
                  name="fatherAge"
                >
                  <InputNumber
                    placeholder="请输入父亲年龄"
                    min={0}
                    max={120}
                    style={{ width: '100%' }}
                  />
                </Form.Item>
                <Form.Item
                  label="情况介绍"
                  name="fatherDesc"
                >
                  <TextArea
                    placeholder="如：职业、收入、老师/在职/退休/经商等"
                    rows={3}
                  />
                </Form.Item>
              </Card>
            </Col>
            <Col span={12}>
              <Card title="母亲情况" size="small">
                <Form.Item
                  label="年龄"
                  name="motherAge"
                >
                  <InputNumber
                    placeholder="请输入母亲年龄"
                    min={0}
                    max={120}
                    style={{ width: '100%' }}
                  />
                </Form.Item>
                <Form.Item
                  label="情况介绍"
                  name="motherDesc"
                >
                  <TextArea
                    placeholder="如：职业、收入、老师/在职/退休/经商等"
                    rows={3}
                  />
                </Form.Item>
              </Card>
            </Col>
          </Row>

          <Divider orientation="left">其他家庭成员</Divider>
          
          <Form.List name="otherMembers">
            {(fields, { add, remove }) => (
              <>
                {fields.map(({ key, name, ...restField }) => (
                  <Card key={key} size="small" style={{ marginBottom: 16 }}>
                    <Row gutter={16} align="middle">
                      <Col span={8}>
                        <Form.Item
                          {...restField}
                          name={[name, 'age']}
                          label="年龄"
                        >
                          <InputNumber
                            placeholder="年龄"
                            min={0}
                            max={120}
                            style={{ width: '100%' }}
                          />
                        </Form.Item>
                      </Col>
                      <Col span={14}>
                        <Form.Item
                          {...restField}
                          name={[name, 'desc']}
                          label="情况介绍"
                        >
                          <Input placeholder="如：兄弟姐妹、职业、收入等" />
                        </Form.Item>
                      </Col>
                      <Col span={2}>
                        <Button
                          type="text"
                          danger
                          icon={<MinusCircleOutlined />}
                          onClick={() => remove(name)}
                        />
                      </Col>
                    </Row>
                  </Card>
                ))}
                <Form.Item>
                  <Button
                    type="dashed"
                    onClick={() => add()}
                    block
                    icon={<PlusOutlined />}
                  >
                    添加其他家庭成员
                  </Button>
                </Form.Item>
              </>
            )}
          </Form.List>
        </Form>
      </Modal>

      {/* 编辑择偶偏好弹窗 */}
      <Modal
        title="编辑择偶偏好"
        open={editPreferenceModalVisible}
        onOk={handleSavePreference}
        onCancel={() => setEditPreferenceModalVisible(false)}
        confirmLoading={loading}
        width={1000}
        style={{ top: 20 }}
        bodyStyle={{ maxHeight: '70vh', overflowY: 'auto' }}
      >
        <Form form={preferenceForm} layout="vertical">
          <Divider orientation="left">择偶标准描述</Divider>
          
          <Form.Item
            label="择偶标准"
            name="standards"
          >
            <TextArea
              placeholder="请描述您的择偶标准"
              rows={4}
            />
          </Form.Item>

          <Divider orientation="left">年龄要求</Divider>
          
          <Row gutter={16}>
            <Col span={6}>
              <Form.Item label="最小年龄" name="minAge">
                <InputNumber
                  placeholder="18"
                  min={18}
                  max={100}
                  style={{ width: '100%' }}
                />
              </Form.Item>
            </Col>
            <Col span={6}>
              <Form.Item label="最大年龄" name="maxAge">
                <InputNumber
                  placeholder="60"
                  min={18}
                  max={100}
                  style={{ width: '100%' }}
                />
              </Form.Item>
            </Col>
            <Col span={6}>
              <Form.Item label="最小出生年份" name="minBrithday">
                <Input placeholder="2000" />
              </Form.Item>
            </Col>
            <Col span={6}>
              <Form.Item label="最大出生年份" name="maxBrithday">
                <Input placeholder="1993" />
              </Form.Item>
            </Col>
          </Row>

          <Divider orientation="left">身体条件要求</Divider>
          
          <Row gutter={16}>
            <Col span={6}>
              <Form.Item label="最低身高 (cm)" name="minHeight">
                <InputNumber
                  placeholder="160"
                  min={100}
                  max={250}
                  style={{ width: '100%' }}
                />
              </Form.Item>
            </Col>
            <Col span={6}>
              <Form.Item label="最高身高 (cm)" name="maxHeight">
                <InputNumber
                  placeholder="180"
                  min={100}
                  max={250}
                  style={{ width: '100%' }}
                />
              </Form.Item>
            </Col>
            <Col span={6}>
              <Form.Item label="最低体重 (斤)" name="minWeight">
                <InputNumber
                  placeholder="90"
                  min={50}
                  max={500}
                  style={{ width: '100%' }}
                />
              </Form.Item>
            </Col>
            <Col span={6}>
              <Form.Item label="最高体重 (斤)" name="maxWeight">
                <InputNumber
                  placeholder="140"
                  min={50}
                  max={500}
                  style={{ width: '100%' }}
                />
              </Form.Item>
            </Col>
          </Row>

          <Divider orientation="left">经济条件要求</Divider>
          
          <Row gutter={16}>
            <Col span={8}>
              <Form.Item label="最低收入 (万元)" name="minIncome">
                <InputNumber
                  placeholder="10"
                  min={0}
                  step={0.1}
                  style={{ width: '100%' }}
                />
              </Form.Item>
            </Col>
            <Col span={8}>
              <Form.Item label="最高收入 (万元)" name="maxIncome">
                <InputNumber
                  placeholder="100"
                  min={0}
                  step={0.1}
                  style={{ width: '100%' }}
                />
              </Form.Item>
            </Col>
          </Row>

          <Row gutter={16}>
            <Col span={12}>
              <Form.Item label="最低学历" name="minEducation">
                <Select placeholder="请选择最低学历" allowClear>
                  <Select.Option value="小学">小学</Select.Option>
                  <Select.Option value="初中">初中</Select.Option>
                  <Select.Option value="高中">高中</Select.Option>
                  <Select.Option value="中专">中专</Select.Option>
                  <Select.Option value="职高">职高</Select.Option>
                  <Select.Option value="技校">技校</Select.Option>
                  <Select.Option value="大专">大专</Select.Option>
                  <Select.Option value="本科">本科</Select.Option>
                  <Select.Option value="硕士">硕士</Select.Option>
                  <Select.Option value="博士">博士</Select.Option>
                  <Select.Option value="博士后">博士后</Select.Option>
                </Select>
              </Form.Item>
            </Col>
            <Col span={12}>
              <Form.Item label="最高学历" name="maxEducation">
                <Select placeholder="请选择最高学历" allowClear>
                  <Select.Option value="小学">小学</Select.Option>
                  <Select.Option value="初中">初中</Select.Option>
                  <Select.Option value="高中">高中</Select.Option>
                  <Select.Option value="中专">中专</Select.Option>
                  <Select.Option value="职高">职高</Select.Option>
                  <Select.Option value="技校">技校</Select.Option>
                  <Select.Option value="大专">大专</Select.Option>
                  <Select.Option value="本科">本科</Select.Option>
                  <Select.Option value="硕士">硕士</Select.Option>
                  <Select.Option value="博士">博士</Select.Option>
                  <Select.Option value="博士后">博士后</Select.Option>
                </Select>
              </Form.Item>
            </Col>
          </Row>

          <Divider orientation="left">职业和地域要求</Divider>
          
          <Form.Item label="职业要求" name="occupationRequire">
            <Select
              mode="tags"
              placeholder="请输入职业要求，支持多个"
              style={{ width: '100%' }}
              tokenSeparators={[',']}
            />
          </Form.Item>

          <Row gutter={16}>
            <Col span={12}>
              <Form.Item label="籍贯要求" name="hometownRequired">
                <Select
                  mode="tags"
                  placeholder="请输入籍贯要求"
                  style={{ width: '100%' }}
                  tokenSeparators={[',']}
                />
              </Form.Item>
            </Col>
            <Col span={12}>
              <Form.Item label="工作地要求" name="currentResidenceRequired">
                <Select
                  mode="tags"
                  placeholder="请输入工作地要求"
                  style={{ width: '100%' }}
                  tokenSeparators={[',']}
                />
              </Form.Item>
            </Col>
          </Row>

          <Divider orientation="left">个性特征和其他要求</Divider>
          
          <Form.Item label="个性特征" name="personalityTraits">
            <Select
              mode="tags"
              placeholder="请输入个性特征要求"
              style={{ width: '100%' }}
              tokenSeparators={[',']}
            />
          </Form.Item>

          <Form.Item label="其他要求" name="otherRequired">
            <Select
              mode="tags"
              placeholder="请输入其他要求"
              style={{ width: '100%' }}
              tokenSeparators={[',']}
            />
          </Form.Item>
        </Form>
      </Modal>

      {/* 发送通知弹窗 */}
      <Modal
        title="发送通知"
        open={messageModalVisible}
        onCancel={() => setMessageModalVisible(false)}
        footer={null}
      >
        <Form
          layout="vertical"
          onFinish={handleSendMessage}
        >
          <Form.Item
            label="通知类型"
            name="type"
            rules={[{ required: true, message: '请选择通知类型' }]}
          >
            <Select placeholder="选择通知类型">
              <Select.Option value="system">系统通知</Select.Option>
              <Select.Option value="promotion">活动推广</Select.Option>
              <Select.Option value="warning">违规警告</Select.Option>
            </Select>
          </Form.Item>
          <Form.Item
            label="通知内容"
            name="content"
            rules={[{ required: true, message: '请输入通知内容' }]}
          >
            <TextArea rows={4} placeholder="请输入要发送的通知内容" />
          </Form.Item>
          <Form.Item>
            <Space>
              <Button type="primary" htmlType="submit" loading={loading}>
                发送
              </Button>
              <Button onClick={() => setMessageModalVisible(false)}>
                取消
              </Button>
            </Space>
          </Form.Item>
        </Form>
      </Modal>
    </div>
  );
};

export default UserDetail;